﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using YiSha.Data.Repository;
using YiSha.Entity.QixingManage;
using YiSha.Model.Param.QixingManage;
using YiSha.Util;
using YiSha.Util.Extension;
using YiSha.Util.Model;

namespace YiSha.Service.QixingManage
{
    public class MemberCouponService: RepositoryFactory
    {
        #region 获取数据
        public async Task<List<MemberCouponEntity>> GetList(MemberCouponListParam param)
        {
            var expression = ListFilter(param);
            var list = await this.BaseRepository().FindList(expression);
            return list.ToList();
        }

        public async Task<List<MemberCouponEntity>> GetPageList(MemberCouponListParam param, Pagination pagination)
        {
            var expression = ListFilter(param);
            var list = await this.BaseRepository().FindList(expression, pagination);
            return list.ToList();
        }

        public async Task<MemberCouponEntity> GetEntity(long id)
        {
            return await this.BaseRepository().FindEntity<MemberCouponEntity>(id);
        }
        #endregion

        #region 提交数据
        public async Task SaveForm(MemberCouponEntity entity)
        {
            if (entity.Id.IsNullOrZero())
            {
                entity.Create();
                await this.BaseRepository().Insert(entity);
            }
            else
            {

                await this.BaseRepository().Update(entity);
            }
        }

        public async Task DeleteForm(string ids)
        {
            long[] idArr = TextHelper.SplitToArray<long>(ids, ',');
            await this.BaseRepository().Delete<MemberCouponEntity>(idArr);
        }

        public async Task DeleteForm(Expression<Func<MemberCouponEntity, bool>> expression)
        {
            await this.BaseRepository().Delete<MemberCouponEntity>(expression);
        }
        #endregion

        #region 私有方法
        private Expression<Func<MemberCouponEntity, bool>> ListFilter(MemberCouponListParam param)
        {
            var expression = LinqExtensions.True<MemberCouponEntity>();
            if (param != null)
            {
            }
            return expression;
        }
        #endregion
    }
}
